//
//  Primitive.cpp
//  RayTracer
//
//  Created by 俞云康 on 4/13/16.
//  Copyright © 2016 yushroom. All rights reserved.
//

#include "Primitive.hpp"
#include "Shape.hpp"
#include "Params.hpp"
#include "Light.hpp"

shared_ptr<GeometricPrimitive> GeometricPrimitive::create(const Params& params) {
    auto shape = Shape::create(params);
    auto material = Material::create(params.child("material"));
	shared_ptr<AreaLight> area_light = nullptr;
	if (params.hasTypedChild("areaLight")) {
		auto area_light = AreaLight::create(params.child("areaLight"));
		auto gp = std::make_shared<GeometricPrimitive>(shape, material, area_light);
		area_light->geometricPrimitive = gp;
		return gp;
	}
	else {
		return std::make_shared<GeometricPrimitive>(shape, material, nullptr);
	}
}